import 'package:flutter/material.dart';
import 'package:aio/aio.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/manager/audit_manager.dart';
import 'package:app/src/presenter/review_presenter.dart';
import 'package:app/src/ui/app_ui.dart';
import 'package:app/src/ui/route/works/public/items/ui_address.dart';
import 'package:app/src/ui/route/works/public/items/ui_attachment.dart';
import 'package:app/src/ui/route/works/public/items/ui_base.dart';
import 'package:app/src/ui/route/works/public/items/ui_contractInfo.dart';
import 'package:app/src/ui/route/works/public/items/ui_customersInfo.dart';
import 'package:app/src/ui/route/works/public/items/ui_new_customer.dart';
import 'package:app/src/ui/route/works/public/items/ui_node_list.dart';
import 'package:app/src/ui/route/works/public/items/ui_note.dart';
import 'package:app/src/ui/route/works/public/items/ui_payment.dart';
import 'package:app/src/ui/route/works/public/acom/ui_product.dart';
import 'package:app/src/ui/route/works/public/items/ui_specialclauses.dart';
import 'package:app/src/ui/route/works/public/review_details_ui.dart';
import 'package:app/src/ui/route/works/public/review_submitted.dart';

///送货地址审核详情
class AuditaddressDetailsRoute extends StatefulWidget {
  AuditaddressDetailsRoute();

  @override
  _State createState() => _State();
}

class _State extends State<AuditaddressDetailsRoute> {
  _Presenter presenter = _Presenter();

  @override
  void initState() {
    super.initState();
    presenter.getContractapplygetinfoWithDelay(context); //获取审核详情数据
  }

  @override
  Widget build(BuildContext context) {
    return ReviewDetailsUi.build(context, presenter, _body);
  }

  Widget _body(BuildContext context) {
    if (presenter?.mDatas == null) {
      return AppUi.getEmptyView();
    }
    List<Widget> children = [];
    children.add(UiContractInfo.build(context, presenter?.mDatas?.ContractInfo,
        presenter?.mOldDatas?.ContractInfo)); //基本信息（合同信息）
    var AddressList = presenter?.mDatas?.AddressList;
    if (AddressList != null) {
      if (AddressList.length == 1) {
        var element = AddressList[0];
        children.add(UiAddress.build(context, element, null)); //送货地址信息
      } else {
        var index = 1;
        AddressList?.forEach((element) {
          children.add(UiAddress.build(context, element, null,
              title: AppStrings.of(context).AddressInformation +
                  index.toString())); //送货地址信息
          index++;
        });
      }
    }

    children.add(UiNoteList.build(context, presenter?.mDatas?.NodeList)); //审核日志
    return Column(
      children: [
        Expanded(child: UiBase.listView(context, children)),
        Visibility(
            child: ReviewSubmittedStateful(
              presenter?.mDatas,
              hasEnd: false,
            ),
            visible: presenter?.mDatas != null)
      ],
    );
  }
}

class _Presenter extends ReviewPresenter {}
